<?php
class deleteRingtoneAction extends sfActions {
	public function execute(){
		if ($this->getRequest()->getMethod() == sfRequest::POST)
		{
			$this->adminId = $this->getUser()->getAttribute('adminId');
			$this->adminLevel = $this->getUser()->getAttribute('adminLevel');
			
			$id 			= makesafe($this->getRequestParameter("id"));
			$deleteStatus 	= $this->getRequestParameter("deleteReason");
			$deleteMessage 	= makeSafe($this->getRequestParameter("deleteMessage"));
			
			$retVal = new stdClass();
			$retVal->success = false;
				
			if ($id != null)
			{
				$cs = new Ringtone();
				$cs->setNew(false);
				$cs->setId($id);
				$cs = RingtonePeer::doSelectOne($cs->buildCriteria());
				
				$deleteStatus = ($deleteStatus == '' ? 5 : $deleteStatus);
				$cs->setDeleted($deleteStatus);
				//$cs->setAdminDeletedId($this->adminId);
				$cs->setCheckoutTime("now");
				//$cs->setDeletedReason($deleteMessage);
				$cs->save();
				
				$ringtoneAlert = new RingtoneAlert();
				$ringtoneAlert->setRingtoneId($id);
				$ringtoneAlert = RingtoneAlertPeer::doSelectOne($ringtoneAlert->buildCriteria());
				if ($ringtoneAlert)
				{
					$ringtoneAlert->delete();
					$retVal->success = true;
				}
				else
				{
					$retVal->success = false;
					break;
				}
				echo FastJSON::encode($retVal);
				
				//write log
				$adminTaskMonitor = new AdminTaskMonitor();
				$adminTaskMonitor->setNew(true);
				$adminTaskMonitor->setAdminId($this->adminId);
				$adminTaskMonitor->setTaskName("Xóa ringtone đã duyệt");
				$adminTaskMonitor->setTaskDescription("Xóa ringtone: " . $cs->getName());
				$adminTaskMonitor->setExcutedTime('now');
				$adminTaskMonitor->save();
			}
		}
		exit();
	}
}
?>